package es.agroservicio.Agroservicio.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import es.agroservicio.Agroservicio.domain.Bill;

@Repository
@Transactional
public class BillsDAOImpl implements BillsDAO {

	private EntityManager em;

    @PersistenceContext
    public void setEntityManager(EntityManager em) {
        this.em = em;
    }
    
	public Bill findById(String id) {
		return em.find(Bill.class, id);
	}

	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")
	public List<Bill> findAllOrderedByName() {
		return em.createQuery("select * from Bill")
				.getResultList();
	}

	public void register(Bill bill) {
		em.persist(bill);
		return;

	}

}
